//
//  DetailWriterViewController.m
//  StanfordEvents
//
//  Created by Gongmyung on 7/7/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "DetailWriterViewController.h"


@implementation DetailWriterViewController

@synthesize delegate;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    //add a border to the textview
    eventDescription.layer.borderWidth = 2;
    eventDescription.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    eventDescription.layer.cornerRadius = 8;
    eventDescription.font = [UIFont systemFontOfSize:14];
    
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
                                     initWithTitle:NSLocalizedString(@"Cancel", @"Cancel - for button to cancel changes")
                                     style:UIBarButtonItemStylePlain
                                     target:self
                                     action:@selector(cancel)];
    self.navigationItem.leftBarButtonItem = cancelButton;
    [cancelButton release];
    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]
                                   initWithTitle:NSLocalizedString(@"Save", @"Save - for button to save changes")
                                   style:UIBarButtonItemStylePlain
                                   target:self
                                   action:@selector(save)];
    self.navigationItem.rightBarButtonItem = saveButton;
    [saveButton release];
    
    self.title = @"Event Details";
    
    [super viewDidLoad];
}

-(IBAction)cancel
{
    [[self.delegate navController] popViewControllerAnimated:YES];
}

-(IBAction)save
{
    [self.delegate setTitle:eventTitle.text andHost:eventHost.text andDescription:eventDescription.text];
    [[self.delegate navController] popViewControllerAnimated:YES];
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)textViewDidBeginEditing:(UITextView *)textView {
    if( [textView.text hasPrefix:@"Event"] ) {
        textView.textColor = [UIColor blackColor];
        textView.text = @"";
        [textView setNeedsDisplay];
    }
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    //[eventTitle release];
    //[eventDescription release];
    //[eventHost release];
    [super dealloc];
}


@end
